package com.link.base.base.superset.service;

import com.link.core.cllog.LCLogger;
import com.link.core.util.RedisUtil;
import com.link.core.util.redisclient.LinkRedisClient;
import org.springframework.stereotype.Service;



/**
 * @author Li Yang
 */
@Service
public class AuthorizeServiceImpl implements AuthorizeService {

    private static final String SUPERSET_TOKEN_KEY = "superset";

    @Override
    public String checkAccessTokenReturnObject(String accessToken) throws Exception {
        String tokenKey = "login_info_" + accessToken;
        LinkRedisClient jedis = RedisUtil.getJedis();
//        JSONObject user = new JSONObject();
        String redisUser = "";
        try {
            redisUser = jedis.hget(tokenKey, SUPERSET_TOKEN_KEY);
//            if (!StringUtils.isBlank(redisUser)) {
//                user = JSONObject.parseObject(redisUser);
//            } else {
//                user.put("info", "未获取到token[" + accessToken + "]对应的用户信息！");
//            }
        } catch (Exception e) {
            LCLogger.withException(e);
            LCLogger.error().withMessageKey("checkAccessTokenReturnObject")
                    .withMessage("通过redis获取user token异常...").flush();
        } finally {
            LCLogger.warn().withMessageKey("checkAccessTokenReturnObject")
                    .withMessage("finally，退出并关闭jedis").flush();
            RedisUtil.returnResource(jedis);
        }
//        return user;
        return redisUser;
    }

}
